//
// Created by ✎﹏ℳ๓独赏 ☆独醉 on 2023/4/20.
//
#include <stdio.h>
void getdata(int arr[],int n){
    int i;
    for(i=0;i<n;i++){
        arr[i]=n-i;
    }
}
void fun(int a[],int l,int r){
    if(l>=r){return;}
     int mid=(l+r)/2,left=l,right=r,temp;
     while(l<r){
         while(a[l]<=a[mid])l++;//这样写的话，枢轴（a[mid]）的值是变动的，排序无准确性
         while(a[r]>a[mid])r--;//需要另外设置一个变量专门记录最初选定的枢轴的值
         if(l<r)temp=a[l],a[l]=a[r],a[r]=temp;
     }
     fun(a,left,r);
     fun(a,r+1,right);
}
int main(){
//    int arr[50]={50,3,6,7,9,5,6,10,45,38,56,52,61,58,59,62,3,5,66,33,180,190,156,52,34,46,28,23,30,79,88,99,11,22,33,45,67,83,45,62,99,100,23,36,37,39,46,52,99,101},i;
//    getdata(arr,50);
    int arr[8]={10,3,9,2,8,2,7,5},i;
    for(i=0;i<8;i++){
        printf("%d ",arr[i]);
    }
    printf("\n");
    fun(arr,0,7);
    for(i=0;i<8;i++){
        printf("%d ",arr[i]);
    }
}